package com.coderman.controller;

import com.coderman.bean.DataBaseBean;
import com.coderman.enums.ErrCodelEnum;
import com.coderman.mapper.DataBaseMapper;
import com.coderman.service.DataBaseService;
import com.coderman.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by ${fanchunshuai} on 2017-6-27.
 *
 * @version: V1.0
 * @Desc:
 * @Copyright (c) 2017 58到家-版权所有
 */
@RestController
@RequestMapping("/dbinfo")
public class DatabaseController {
    @Autowired
    private DataBaseService dataBaseService;

    @RequestMapping("/getone")
    public DataBaseBean getUser(Long id) {
       /* DataBaseBean dataBaseBean = dataBaseMapper.getOne(id);
        return dataBaseBean;*/
        return null;
    }

    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public String save(DataBaseBean dataBaseBean) {
        dataBaseBean.setStatus(0);
        dataBaseBean.setCharSet("utf-8");
        dataBaseBean.setPort("3306");
        System.out.println(dataBaseBean.toString());
        return dataBaseService.save(dataBaseBean);
    }

    @RequestMapping("/initdb/{id}")
    public String createDb(@PathVariable("id") Long id) {
        return dataBaseService.createDataBase(id);
    }

    @RequestMapping("/pagelist")
    public String getPageList(){
        return JsonResult.parseRqtMsg(ErrCodelEnum.success.getCode(),dataBaseService.getPageList());
    }



}
